{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exploring the WMS with OWSLib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CRW_DHW\n",
      "CRW_DHW_mask\n",
      "CRW_HOTSPOT\n",
      "CRW_HOTSPOT_mask\n",
      "CRW_SSTANOMALY\n",
      "CRW_SSTANOMALY_mask\n",
      "CRW_BAA\n",
      "CRW_BAA_mask\n",
      "CRW_BAA_7D_MAX\n",
      "CRW_BAA_7D_MAX_mask\n",
      "CRW_SEAICE\n",
      "CRW_SST\n"
     ]
    }
   ],
   "source": [
    "from owslib.wms import WebMapService\n",
    "\n",
    "\n",
    "url = \"https://pae-paha.pacioos.hawaii.edu/thredds/wms/dhw_5km?service=WMS\"\n",
    "\n",
    "web_map_services = WebMapService(url)\n",
    "\n",
    "print(\"\\n\".join(web_map_services.contents.keys()))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Layer metadata"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "layer = \"CRW_SST\"\n",
    "wms = web_map_services.contents[layer]\n",
    "\n",
    "name = wms.title\n",
    "\n",
    "lon = (wms.boundingBox[0] + wms.boundingBox[2]) / 2.0\n",
    "lat = (wms.boundingBox[1] + wms.boundingBox[3]) / 2.0\n",
    "center = lat, lon\n",
    "\n",
    "time_interval = \"{0}/{1}\".format(\n",
    "    wms.timepositions[0].strip(), wms.timepositions[-1].strip()\n",
    ")\n",
    "style = \"boxfill/sst_36\"\n",
    "\n",
    "if style not in wms.styles:\n",
    "    style = None"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Single layer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><span style=\"color:#565656\">Make this Notebook Trusted to load map: File -> Trust Notebook</span><iframe src=\"about:blank\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" data-html=PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgCiAgICAgICAgPHNjcmlwdD4KICAgICAgICAgICAgTF9OT19UT1VDSCA9IGZhbHNlOwogICAgICAgICAgICBMX0RJU0FCTEVfM0QgPSBmYWxzZTsKICAgICAgICA8L3NjcmlwdD4KICAgIAogICAgPHN0eWxlPmh0bWwsIGJvZHkge3dpZHRoOiAxMDAlO2hlaWdodDogMTAwJTttYXJnaW46IDA7cGFkZGluZzogMDt9PC9zdHlsZT4KICAgIDxzdHlsZT4jbWFwIHtwb3NpdGlvbjphYnNvbHV0ZTt0b3A6MDtib3R0b206MDtyaWdodDowO2xlZnQ6MDt9PC9zdHlsZT4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS42LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NvZGUuanF1ZXJ5LmNvbS9qcXVlcnktMS4xMi40Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3RyYXAvMy4yLjAvanMvYm9vdHN0cmFwLm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvTGVhZmxldC5hd2Vzb21lLW1hcmtlcnMvMi4wLjIvbGVhZmxldC5hd2Vzb21l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aGxpZ2h0LmpzLzguNC9zdHlsZXMvZGVmYXVsdC5taW4uY3NzIi8+CiAgICA8bGluayByZWw9InN0eWxlc2hlZXQiIGhyZWY9Imh0dHBzOi8vY2RuLmpzZGVsaXZyLm5ldC9ucG0vbGVhZmxldC10aW1lZGltZW5zaW9uQDEuMS4xL2Rpc3QvbGVhZmxldC50aW1lZGltZW5zaW9uLmNvbnRyb2wuY3NzIi8+CjwvaGVhZD4KPGJvZHk+ICAgIAogICAgCiAgICAgICAgICAgIDxkaXYgY2xhc3M9ImZvbGl1bS1tYXAiIGlkPSJtYXBfNTlhMTliMWI3MDA4NDhiZTgwNTQ1NmIxNjBlOTM5ZTAiID48L2Rpdj4KICAgICAgICAKPC9ib2R5Pgo8c2NyaXB0PiAgICAKICAgIAogICAgICAgICAgICB2YXIgbWFwXzU5YTE5YjFiNzAwODQ4YmU4MDU0NTZiMTYwZTkzOWUwID0gTC5tYXAoCiAgICAgICAgICAgICAgICAibWFwXzU5YTE5YjFiNzAwODQ4YmU4MDU0NTZiMTYwZTkzOWUwIiwKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBjZW50ZXI6IFstNDAuMCwgLTUwLjBdLAogICAgICAgICAgICAgICAgICAgIGNyczogTC5DUlMuRVBTRzM4NTcsCiAgICAgICAgICAgICAgICAgICAgem9vbTogNSwKICAgICAgICAgICAgICAgICAgICB6b29tQ29udHJvbDogdHJ1ZSwKICAgICAgICAgICAgICAgICAgICBwcmVmZXJDYW52YXM6IGZhbHNlLAogICAgICAgICAgICAgICAgfQogICAgICAgICAgICApOwogICAgICAgICAgICBMLmNvbnRyb2wuc2NhbGUoKS5hZGRUbyhtYXBfNTlhMTliMWI3MDA4NDhiZTgwNTQ1NmIxNjBlOTM5ZTApOwoKICAgICAgICAgICAgCgogICAgICAgIAogICAgCiAgICAgICAgICAgIHZhciB0aWxlX2xheWVyX2RhODI1ZTNiNDJiMzQ0ODk5NWY3ZmM5ZWVlZDMyODQyID0gTC50a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5zcGFyZW50IjogdHJ1ZSwgInZlcnNpb24iOiAiMS4xLjEifQogICAgICAgICAgICApLmFkZFRvKG1hcF81OWExOWIxYjcwMDg0OGJlODA1NDU2YjE2MGU5MzllMCk7CiAgICAgICAgCiAgICAKICAgICAgICAgICAgbWFwXzU5YTE5YjFiNzAwODQ4YmU4MDU0NTZiMTYwZTkzOWUwLnRpbWVEaW1lbnNpb24gPSBMLnRpbWVEaW1lbnNpb24oCiAgICAgICAgICAgICAgICB7InBlcmlvZCI6ICJQVDFIIiwgInRpbWVJbnRlcnZhbCI6ICIxOTg1LTA0LTAxVDEyOjAwOjAwLjAwMFovMjAyMC0xMS0xNFQxMjowMDowMC4wMDBaIn0KICAgICAgICAgICAgKTsKICAgICAgICAgICAgbWFwXzU5YTE5YjFiNzAwODQ4YmU4MDU0NTZiMTYwZTkzOWUwLnRpbWVEaW1lbnNpb25Db250cm9sID0KICAgICAgICAgICAgICAgIEwuY29udHJvbC50aW1lRGltZW5zaW9uKAogICAgICAgICAgICAgICAgICAgIHsiYXV0b1BsYXkiOiBmYWxzZSwgInBsYXllck9wdGlvbnMiOiB7Imxvb3AiOiBmYWxzZSwgInRyYW5zaXRpb25UaW1lIjogMjAwfSwgInBvc2l0aW9uIjogImJvdHRvbWxlZnQifQogICAgICAgICAgICAgICAgKTsKICAgICAgICAgICAgbWFwXzU5YTE5YjFiNzAwODQ4YmU4MDU0NTZiMTYwZTkzOWUwLmFkZENvbnRyb2woCiAgICAgICAgICAgICAgICBtYXBfNTlhMTliMWI3MDA4NDhiZTgwNTQ1NmIxNjBlOTM5ZTAudGltZURpbWVuc2lvbkNvbnRyb2wKICAgICAgICAgICAgKTsKCiAgICAgICAgICAgIAogICAgICAgICAgICB2YXIgbWFjcm9fZWxlbWVudF8yOTZmOTk3YWYwN2I0NGVmYWM4ZjFmYWZjZDI3YmZhZSA9IEwudGltZURpbWVuc2lvbi5sYXllci53bXMoCiAgICAgICAgICAgICAgICBtYWNyb19lbGVtZW50XzI5NmY5OTdhZjA3YjQ0ZWZhYzhmMWZhZmNkMjdiZmFlLAogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIHVwZGF0ZVRpbWVEaW1lbnNpb246IGZhbHNlLAogICAgICAgICAgICAgICAgICAgIHdtc1ZlcnNpb246ICIxLjEuMSIsCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICkuYWRkVG8obWFwXzU5YTE5YjFiNzAwODQ4YmU4MDU0NTZiMTYwZTkzOWUwKTsKICAgICAgICAgICAgCiAgICAgICAgCiAgICAKICAgICAgICAgICAgdmFyIGxheWVyX2NvbnRyb2xfNDM1MGM3YmE5ZmUxNDk1YWE4MDQ5ZmIzZTRhMGM1YWYgPSB7CiAgICAgICAgICAgICAgICBiYXNlX2xheWVycyA6IHsKICAgICAgICAgICAgICAgICAgICAib3BlbnN0cmVldG1hcCIgOiB0aWxlX2xheWVyX2RhODI1ZTNiNDJiMzQ0ODk5NWY3ZmM5ZWVlZDMyODQyLAogICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgIG92ZXJsYXlzIDogIHsKICAgICAgICAgICAgICAgICAgICAic2VhX3N1cmZhY2VfdGVtcGVyYXR1cmUiIDogbWFjcm9fZWxlbWVudF8yOTZmOTk3YWYwN2I0NGVmYWM4ZjFmYWZjZDI3YmZhZSwKICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgIH07CiAgICAgICAgICAgIEwuY29udHJvbC5sYXllcnMoCiAgICAgICAgICAgICAgICBsYXllcl9jb250cm9sXzQzNTBjN2JhOWZlMTQ5NWFhODA0OWZiM2U0YTBjNWFmLmJhc2VfbGF5ZXJzLAogICAgICAgICAgICAgICAgbGF5ZXJfY29udHJvbF80MzUwYzdiYTlmZTE0OTVhYTgwNDlmYjNlNGEwYzVhZi5vdmVybGF5cywKICAgICAgICAgICAgICAgIHsiYXV0b1pJbmRleCI6IHRydWUsICJjb2xsYXBzZWQiOiB0cnVlLCAicG9zaXRpb24iOiAidG9wcmlnaHQifQogICAgICAgICAgICApLmFkZFRvKG1hcF81OWExOWIxYjcwMDg0OGJlODA1NDU2YjE2MGU5MzllMCk7CiAgICAgICAgCjwvc2NyaXB0Pg== onload=\"this.contentDocument.open();this.contentDocument.write(atob(this.getAttribute('data-html')));this.contentDocument.close();\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x7fa2e80cbb20>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import folium\n",
    "from folium import plugins\n",
    "\n",
    "lon, lat = -50, -40\n",
    "\n",
    "m = folium.Map(location=[lat, lon], zoom_start=5, control_scale=True)\n",
    "\n",
    "w = folium.raster_layers.WmsTileLayer(\n",
    "    url=url,\n",
    "    name=name,\n",
    "    styles=style,\n",
    "    fmt=\"image/png\",\n",
    "    transparent=True,\n",
    "    layers=layer,\n",
    "    overlay=True,\n",
    "    COLORSCALERANGE=\"1.2,28\",\n",
    ")\n",
    "\n",
    "w.add_to(m)\n",
    "\n",
    "time = plugins.TimestampedWmsTileLayers(w, period=\"PT1H\", time_interval=time_interval)\n",
    "\n",
    "time.add_to(m)\n",
    "\n",
    "folium.LayerControl().add_to(m)\n",
    "\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Multiple layers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><span style=\"color:#565656\">Make this Notebook Trusted to load map: File -> Trust Notebook</span><iframe src=\"about:blank\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" data-html=PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaG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vaGVhZD4KPGJvZHk+ICAgIAogICAgCiAgICAgICAgICAgIDxkaXYgY2xhc3M9ImZvbGl1bS1tYXAiIGlkPSJtYXBfZmFiMjczYTQ5Nzg2NDYwN2E0M2ZjNmM5NTRhYjMzYWMiID48L2Rpdj4KICAgICAgICAKPC9ib2R5Pgo8c2NyaXB0PiAgICAKICAgIAogICAgICAgICAgICB2YXIgbWFwX2ZhYjI3M2E0OTc4NjQ2MDdhNDNmYzZjOTU0YWIzM2FjID0gTC5tYXAoCiAgICAgICAgICAgICAgICAibWFwX2ZhYjI3M2E0OTc4NjQ2MDdhNDNmYzZjOTU0YWIzM2FjIiwKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBjZW50ZXI6IFstNDAuMCwgLTUwLjBdLAogICAgICAgICAgICAgICAgICAgIGNyczogTC5DUlMuRVBTRzM4NTcsCiAgICAgICAgICAgICAgICAgICAgem9vbTogNSwKICAgICAgICAgICAgICAgICAgICB6b29tQ29udHJvbDogdHJ1ZSwKICAgICAgICAgICAgICAgICAgICBwcmVmZXJDYW52YXM6IGZhbHNlLAogICAgICAgICAgICAgICAgfQogICAgICAgICAgICApOwogICAgICAgICAgICBMLmNvbnRyb2wuc2NhbGUoKS5hZGRUbyhtYXBfZmFiMjczYTQ5Nzg2NDYwN2E0M2ZjNmM5NTRhYjMzYWMpOwoKICAgICAgICAgICAgCgogICAgICAgIAogICAgCiAgICAgICAgICAgIHZhciB0aWxlX2xheWVyX2IzMmFkMWE1YTQxZDRhYjI4ZTU4YmM5MWE2NmExNDhjID0gTC50aWxlTGF5ZXIoCiAgICAgICAgICAgICAgICAiaHR0cHM6Ly97c30udGlsZS5vcGVuc3RyZWV0bWFwLm9yZy97en0ve3h9L3t5fS5wbmciLAogICAgICAgICAgICAgICAgeyJhdHRyaWJ1dGlvbiI6ICJEYXRhIGJ5IFx1MDAyNmNvcHk7IFx1MDAzY2EgaHJlZj1cImh0dHA6Ly9vcGVuc3RyZWV0bWFwLm9yZ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ICAgICAgICAgICAgImh0dHBzOi8vcGFlLXBhaGEucGFjaW9vcy5oYXdhaWkuZWR1L3RocmVkZHMvd21zL2Rod181a20/c2VydmljZT1XTVMiLAogICAgICAgICAgICAgICAgeyJhdHRyaWJ1dGlvbiI6ICIiLCAiZm9ybWF0IjogImltYWdlL3BuZyIsICJsYXllcnMiOiAiQ1JXX1NTVEFOT01BTFkiLCAic3R5bGVzIjogImJveGZpbGwvc3N0XzM2IiwgInRyYW5zcGFyZW50IjogdHJ1ZSwgInZlcnNpb24iOiAiMS4xLjEifQogICAgICAgICAgICApLmFkZFRvKG1hcF9mYWIyNzNhNDk3ODY0NjA3YTQzZmM2Yzk1NGFiMzNhYyk7CiAgICAgICAgCiAgICAKICAgICAgICAgICAgbWFwX2ZhYjI3M2E0OTc4NjQ2MDdhNDNmYzZjOTU0YWIzM2FjLnRpbWVEaW1lbnNpb24gPSBMLnRpbWVEaW1lbnNpb24oCiAgICAgICAgICAgICAgICB7InBlcmlvZCI6ICJQVDFIIiwgInRpbWVJbnRlcnZhbCI6ICIxOTg1LTA0LTAxVDEyOjAwOjAwLjAwMFovMjAyMC0xMS0xNFQxMjowMDowMC4wMDBaIn0KICAgICAgICAgICAgKTsKICAgICAgICAgICAgbWFwX2ZhYjI3M2E0OTc4NjQ2MDdhNDNmYzZjOTU0YWIzM2FjLnRpbWVEaW1lbnNpb25Db250cm9sID0KICAgICAgICAgICAgICAgIEwuY29udHJvbC50aW1lRGltZW5zaW9uKAogICAgICAgICAgICAgICAgICAgIHsiYXV0b1BsYXkiOiBmYWxzZSwgInBsYXllck9wdGlvbnMiOiB7Imxvb3AiOiBmYWxzZSwgInRyYW5zaXRpb25UaW1lIjogMjAwfSwgInBvc2l0aW9uIjogImJvdHRvbWxlZnQifQogICAgICAgICAgICAgICAgKTsKICAgICAgICAgICAgbWFwX2ZhYjI3M2E0OTc4NjQ2MDdhNDNmYzZjOTU0YWIzM2FjLmFkZENvbnRyb2woCiAgICAgICAgICAgICAgICBtYXBfZmFiMjczYTQ5Nzg2NDYwN2E0M2ZjNmM5NTRhYjMzYWMudGltZURpbWVuc2lvbkNvbnRyb2wKICAgICAgICAgICAgKTsKCiAgICAgICAgICAgIAogICAgICAgICAgICB2YXIgbWFjcm9fZWxlbWVudF9lNWY0ZDhlNWRlNDI0NzVhYjBhMjBkYWQ5ZjZkNTZlYiA9IEwudGltZURpbWVuc2lvbi5sYXllci53bXMoCiAgICAgICAgICAgICAgICBtYWNyb19lbGVtZW50X2U1ZjRkOGU1ZGU0MjQ3NWFiMGEyMGRhZDlmNmQ1NmViLAogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIHVwZGF0ZVRpbWVEaW1lbnNpb246IGZhbHNlLAogICAgICAgICAgICAgICAgICAgIHdtc1ZlcnNpb246ICIxLjEuMSIsCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICkuYWRkVG8obWFwX2ZhYjI3M2E0OTc4NjQ2MDdhNDNmYzZjOTU0YWIzM2FjKTsKICAgICAgICAgICAgCiAgICAgICAgICAgIHZhciBtYWNyb19lbGVtZW50X2JjNmEwMWI0ZjFiMDQxM2ZiZTRiYzE1YjliZTI0MmNjID0gTC50aW1lRGltZW5zaW9uLmxheWVyLndtcygKICAgICAgICAgICAgICAgIG1hY3JvX2VsZW1lbnRfYmM2YTAxYjRmMWIwNDEzZmJlNGJjMTViOWJlMjQyY2MsCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgdXBkYXRlVGltZURpbWVuc2lvbjogZmFsc2UsCiAgICAgICAgICAgICAgICAgICAgd21zVmVyc2lvbjogIjEuMS4xIiwKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgKS5hZGRUbyhtYXBfZmFiMjczYTQ5Nzg2NDYwN2E0M2ZjNmM5NTRhYjMzYWMpOwogICAgICAgICAgICAKICAgICAgICAKICAgIAogICAgICAgICAgICB2YXIgbGF5ZXJfY29udHJvbF84ODI1NjNmNDg4Y2Y0MGNiOGE1OGVmYmYxNTdhYmJjZCA9IHsKICAgICAgICAgICAgICAgIGJhc2VfbGF5ZXJzIDogewogICAgICAgICAgICAgICAgICAgICJvcGVuc3RyZWV0bWFwIiA6IHRpbGVfbGF5ZXJfYjMyYWQxYTVhNDFkNGFiMjhlNThiYzkxYTY2YTE0OGMsCiAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICAgb3ZlcmxheXMgOiAgewogICAgICAgICAgICAgICAgICAgICJzZWFfc3VyZmFjZV90ZW1wZXJhdHVyZSIgOiBtYWNyb19lbGVtZW50X2U1ZjRkOGU1ZGU0MjQ3NWFiMGEyMGRhZDlmNmQ1NmViLAogICAgICAgICAgICAgICAgICAgICJhbmFseXNlZCBzZWEgc3VyZmFjZSB0ZW1wZXJhdHVyZSBhbm9tYWx5IiA6IG1hY3JvX2VsZW1lbnRfYmM2YTAxYjRmMWIwNDEzZmJlNGJjMTViOWJlMjQyY2MsCiAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICB9OwogICAgICAgICAgICBMLmNvbnRyb2wubGF5ZXJzKAogICAgICAgICAgICAgICAgbGF5ZXJfY29udHJvbF84ODI1NjNmNDg4Y2Y0MGNiOGE1OGVmYmYxNTdhYmJjZC5iYXNlX2xheWVycywKICAgICAgICAgICAgICAgIGxheWVyX2NvbnRyb2xfODgyNTYzZjQ4OGNmNDBjYjhhNThlZmJmMTU3YWJiY2Qub3ZlcmxheXMsCiAgICAgICAgICAgICAgICB7ImF1dG9aSW5kZXgiOiB0cnVlLCAiY29sbGFwc2VkIjogdHJ1ZSwgInBvc2l0aW9uIjogInRvcHJpZ2h0In0KICAgICAgICAgICAgKS5hZGRUbyhtYXBfZmFiMjczYTQ5Nzg2NDYwN2E0M2ZjNmM5NTRhYjMzYWMpOwogICAgICAgIAo8L3NjcmlwdD4= onload=\"this.contentDocument.open();this.contentDocument.write(atob(this.getAttribute('data-html')));this.contentDocument.close();\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x7fa28c2dd130>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = folium.Map(location=[lat, lon], zoom_start=5, control_scale=True)\n",
    "\n",
    "w0 = folium.raster_layers.WmsTileLayer(\n",
    "    url=url,\n",
    "    name=\"sea_surface_temperature\",\n",
    "    styles=style,\n",
    "    fmt=\"image/png\",\n",
    "    transparent=True,\n",
    "    layers=\"CRW_SST\",\n",
    "    overlay=True,\n",
    ")\n",
    "\n",
    "w1 = folium.raster_layers.WmsTileLayer(\n",
    "    url=url,\n",
    "    name=\"analysed sea surface temperature anomaly\",\n",
    "    styles=style,\n",
    "    fmt=\"image/png\",\n",
    "    transparent=True,\n",
    "    layers=\"CRW_SSTANOMALY\",\n",
    "    overlay=True,\n",
    ")\n",
    "\n",
    "w0.add_to(m)\n",
    "w1.add_to(m)\n",
    "\n",
    "time = folium.plugins.TimestampedWmsTileLayers(\n",
    "    [w0, w1], period=\"PT1H\", time_interval=time_interval\n",
    ")\n",
    "\n",
    "time.add_to(m)\n",
    "\n",
    "folium.LayerControl().add_to(m)\n",
    "\n",
    "m"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
